import os
import sys
absp=os.path.abspath(__file__)
absdir=os.path.dirname(absp)
pathdir=os.path.dirname(absdir + '/../..')
sys.path.append(pathdir)

from basefunctions import BaseFunctions
import unittest

class  BaseFunctions_TestCase(unittest.TestCase):
    def setUp(self):
        """
        Initial values
        """
        # u = 0.5
        self.u = 10*10*0.1/(4*0.05*100)
        # a = 0.1
        self.a = 10.0/(100*30/0.3)**0.5
        self.bf = BaseFunctions()

    def tearDown(self):
        #self.bf.dispose()
        self.bf = None

    def test_basefunctions_wu(self):
        # wu(0.5) = 0.5598
        w1=self.bf.wu_integrate(self.u)[0]
        w2=self.bf.wu_series(self.u)[0]
        self.assertEqual(round(w1,4), 0.5598)
        self.assertEqual(round(w2,4), 0.5598)
        # wu(0.00003) = 9.8371
        w3=self.bf.wu_integrate(0.00003)[0]
        w4=self.bf.wu_series(0.00003)[0]
        self.assertEqual(round(w3,4), 9.8371)
        self.assertEqual(round(w4,4), 9.8371)

    def test_basefunctions_wua(self):
        # wua(0.5,0.1) = 0.5581        
        w1=self.bf.wua_integrate(self.u,self.a)[0]
        self.assertEqual(round(w1,4), 0.5581)
        # wua(0.6,0.001) = 0.4544
        w2=self.bf.wua_integrate(0.6,0.001)[0]        
        self.assertEqual(round(w2,4), 0.4544)

    def test_basefunctions_linear_interpolation(self):
        # wua(0.5,0.1) = 0.5581
        pa = [1.25,2]
        pb = [5.32,-4.125]
        x = 6
        v=self.bf.linear_interpolation(x,pa,pb)
        self.assertEqual(v, None)
        x = 1
        v=self.bf.linear_interpolation(x,pa,pb)
        self.assertEqual(v, None)
        x = 1.2500001
        v=self.bf.linear_interpolation(x,pa,pb)
        self.assertEqual(round(v,4), 2.0000)
        x = 5.3199999
        v=self.bf.linear_interpolation(x,pa,pb)
        self.assertEqual(round(v,4), -4.1250)
        x = 3.285
        v=self.bf.linear_interpolation(x,pa,pb)
        self.assertEqual(round(v,4), -1.0625)

if __name__ == '__main__':
    unittest.main()

